
from app import db
from passlib.apps import custom_app_context as pwd_context
from datetime import datetime
from app.common.common import random_str
from app.models.shop_list import *
#顾客表
class Staff(db.Model):
    __tablename__ = 'staff'
    userId = db.Column(db.BigInteger,primary_key = True)# 手机号登录名
    loginPwd = db.Column(db.Text,nullable=False) #密码
    userNickName = db.Column(db.String(50),default='如你用户') #用户昵称
    userPhone = db.Column(db.BigInteger) #电话 同登录名
    lastTime = db.Column(db.DateTime,default=datetime.now()) #最后登录时间
    createTime = db.Column(db.DateTime,default=datetime.now()) #创建时间
    userPhoto = db.Column(db.Text,default='/static/img/moren_tx.jpg')
    adresss = db.relationship('Adress_list',backref=db.backref('staff'))
    orders = db.relationship('Order_list',backref=db.backref('staff'))
    def hash_password(self, password):
        self.loginPwd = pwd_context.encrypt(password)
    def verify_password(self, password):
        return pwd_context.verify(password, self.loginPwd)

#用户地址表
class Adress_list(db.Model):
    __tablename__ = 'adress_list'
    id = db.Column(db.Integer,primary_key = True,autoincrement=True)
    addressId = db.Column(db.String(64),default='none')
    userName = db.Column(db.String(50)) #收货人名称
    userPhone = db.Column(db.String(20)) #收货人手机
    areaIdPath = db.Column(db.Text) #区域id路径 省Id_市Id_县Id 例如:440000_440100_440106
    areaId = db.Column(db.String(6)) #最后一级区域id
    userAddress = db.Column(db.Text) #详细地址
    isDefault = db.Column(db.Integer,default=1) # 默认 0:否 1:是
    dataFlag =  db.Column(db.Integer,default=1) #有效状态  1有效 -1无效
    createTime = db.Column(db.DateTime,default=datetime.now()) #创建时间
    userId  = db.Column(db.BigInteger,db.ForeignKey('staff.userId'))
    
#地址码表
class ChinaAdress(db.Model):
    __tablename__ = 'chinaadress'
    id = db.Column(db.Integer,primary_key = True,autoincrement=True)
    name = db.Column(db.String(32)) #收货人名称
    value = db.Column(db.Integer)
    parent = db.Column(db.Integer)
















